/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package aso.upna.threads;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author triki
 */
public class ServerListenerThread implements Runnable {
    private ServerSocket sock;

    public ServerListenerThread(int port)
    {
        try {
            sock = new ServerSocket(port);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public void run() {

        while(true)
        {
            try {
                
                System.out.println("Esperando clientes");
                Socket s = sock.accept();
                System.out.println("Cliente aceptado");
                ClientAcceptedThread hiloCli = new ClientAcceptedThread(s,"./");
                Thread cliThread = new Thread(hiloCli);
                cliThread.start();
                
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

}
